package com.cman777.springc.mybatis.util;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.cman777.springc.common.bean.enums.StateEnum;
import com.cman777.springc.web.holder.RequestInfoHolder;

import java.time.LocalDateTime;
import java.util.Optional;

/**
 * @author chenzhicong
 * @time 2020/3/16 18:22
 * @description
 */
public class WrapperUtil {
    /**
      * 手动填充
      */
    public static UpdateWrapper handlerUpdateWrapper4LogicRemove(UpdateWrapper updateWrapper){
        updateWrapper.set("state", StateEnum.INVALID);
        updateWrapper.set("state_date", LocalDateTime.now());
        updateWrapper.set("operator_id", Optional.ofNullable(RequestInfoHolder.getOperatorId())
                .filter(o-> StringUtils.isBlank(o)).orElse("anonymous"));
        return updateWrapper;
    }
}
